#include"FieldGenerator.h" 

#include"Field.h"
#include"Map.h"//TODO This is only for NUM_ROWS and NUM_COLS, should prolly be a shared defines include or so.

#include<assert.h>

#define CHANCE_BUSH	.1
#define CHANCE_FOREST	.05
#define CHANCE_HILLS	.05
#define CHANCE_ROCKS	.05
#define CHANCE_SWAMP	.05
#define CHANCE_WATER	.05
#define CHANCE_GRASS	(1.0-CHANCE_BUSH-CHANCE_FOREST-CHANCE_HILLS-CHANCE_ROCKS-CHANCE_SWAMP-CHANCE_WATER)

FieldGenerator::FieldGenerator(){
	
}

FieldGenerator::~FieldGenerator(){
	
}

Field *FieldGenerator::getField(int row, int col){
	//TODO Swamp may only attach to water, it seams
	//TODO Outer 4 cols may only contain grass, except, say, outer 8 rows
	if( (col < 2 || col >= NUM_COLS - 2) && (row >= 3 && row < NUM_ROWS - 3) )
		return Field::getField(FIELD_GRASS, row, col);
	
	double r = rand() / (double)RAND_MAX;
	if(r < CHANCE_GRASS)
		return Field::getField(FIELD_GRASS, row, col);
	r -= CHANCE_GRASS;
	if(r < CHANCE_BUSH)
		return Field::getField(FIELD_BUSH, row, col);
	r -= CHANCE_BUSH;
	if(r < CHANCE_FOREST)
		return Field::getField(FIELD_FOREST, row, col);
	r -= CHANCE_FOREST;
	if(r < CHANCE_HILLS)
		return Field::getField(FIELD_HILLS, row, col);
	r -= CHANCE_HILLS;
	if(r < CHANCE_ROCKS)
		return Field::getField(FIELD_ROCKS, row, col);
	r -= CHANCE_ROCKS;
	if(r < CHANCE_SWAMP)
		return Field::getField(FIELD_SWAMP, row, col);
	r -= CHANCE_SWAMP;
	assert(r < CHANCE_WATER);
	return Field::getField(FIELD_WATER, row, col);
}
